package cn.maxhou.crm.service.Impl;

import cn.maxhou.crm.entity.User;
import cn.maxhou.crm.mapper.UserMapper;
import cn.maxhou.crm.service.IUserService;
import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements IUserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(String usrName, String usrPassword) {
        User user=userMapper.getUserByUsrNameWithRoleName(usrName);
        if (user!=null){//判断用户是否存在
            //判断密码是否正确
            if (user.getUsrPassword().equals(usrPassword)){
                return user;
            }
        }
        return null;
    }

    @Override
    public int addUser(User user) {
        return userMapper.insert(user);
    }

    @Override
    public int deleteUser(int id) {
        return userMapper.deleteById(id);
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateById(user);
    }

    @Override
    public User getUser(Long usrId) {
        return userMapper.selectById(usrId);
    }

    @Override
    public List<User> findAllUsers() {
        return userMapper.getUserListWithRoleName();
    }
}
